/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * TelaSemivariograma.java
 *
 * Created on 26/05/2010, 13:14:03
 */
package visao;

import java.awt.Color;
import javax.swing.JMenuItem;
import javax.swing.JSlider;
import javax.swing.JTextField;

/**
 *
 * @author Hemerson
 */
public class TelaSemivariograma extends javax.swing.JInternalFrame {

    Parametros param;
    int width = 500;
    int height = 400;
    JMenuItem jMenuItemAG;

    /** Creates new form TelaSemivariograma */
    public TelaSemivariograma(Parametros param, JMenuItem jMenuItemAG) {
        initComponents();
        this.jMenuItemAG = jMenuItemAG;
        this.param = param;
        param.setAtualiza(jTextFieldMMQ, "00000.00");
        param.setUmax(width);
        param.setVmax(height);
        param.setXmax(width);
        param.setYmax(height);
        jTextFieldMMQ.setBackground(Color.WHITE);
        ((Desenho) jPanelDesenho).setaVariaveis(param, height, width);
        jTextFieldMMQ.setText("" + param.getModelo().getMmq());
        jSliderAlcance.setValue(jSliderAlcance.getMaximum() / 2);
        jSliderEfeitoPepita.setValue(0);
        jSliderContribuicao.setValue(2200);
        jComboBoxMetodo.setSelectedIndex(0);
        jComboBoxModelo.setSelectedIndex(0);
        jPanelDesenho.repaint();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jPanelDesenho = jPanelDesenho = new Desenho();
        jComboBoxModelo = new javax.swing.JComboBox();
        jComboBoxMetodo = new javax.swing.JComboBox();
        jTextFieldMMQ = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jPanel4 = new javax.swing.JPanel();
        jTextFieldAlcance = new javax.swing.JTextField();
        jSliderAlcance = new javax.swing.JSlider();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jSliderEfeitoPepita = new javax.swing.JSlider();
        jTextFieldEfeitoPepita = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        jSliderContribuicao = new javax.swing.JSlider();
        jTextFieldContribuicao = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        jSliderCutOff = new javax.swing.JSlider();
        jTextFieldCutOff = new javax.swing.JTextField();

        setClosable(true);
        setDefaultCloseOperation(javax.swing.WindowConstants.HIDE_ON_CLOSE);
        setTitle("Software SEMAG v1.0 - Semivariograma");

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));
        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.RAISED));

        jPanelDesenho.setBackground(new java.awt.Color(255, 255, 255));
        jPanelDesenho.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Pairwise", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), new java.awt.Color(0, 0, 153))); // NOI18N

        javax.swing.GroupLayout jPanelDesenhoLayout = new javax.swing.GroupLayout(jPanelDesenho);
        jPanelDesenho.setLayout(jPanelDesenhoLayout);
        jPanelDesenhoLayout.setHorizontalGroup(
            jPanelDesenhoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 488, Short.MAX_VALUE)
        );
        jPanelDesenhoLayout.setVerticalGroup(
            jPanelDesenhoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 373, Short.MAX_VALUE)
        );

        jComboBoxModelo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Modelo", "Circular", "Esferico", "Exponencial", "Gaussiano", "Linear" }));
        jComboBoxModelo.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jComboBoxModeloItemStateChanged(evt);
            }
        });

        jComboBoxMetodo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Metodo", "Cressie", "Matheron", "Pairwise" }));
        jComboBoxMetodo.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jComboBoxMetodoItemStateChanged(evt);
            }
        });

        jTextFieldMMQ.setEditable(false);
        jTextFieldMMQ.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTextFieldMMQ.setText("00.0000");

        jLabel4.setText("MMQ:");

        jPanel4.setBackground(new java.awt.Color(211, 211, 252));

        jTextFieldAlcance.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTextFieldAlcance.setText("246");
        jTextFieldAlcance.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldAlcanceActionPerformed(evt);
            }
        });
        jTextFieldAlcance.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                jTextFieldAlcanceFocusGained(evt);
            }
        });

        jSliderAlcance.setBackground(new java.awt.Color(211, 211, 252));
        jSliderAlcance.setMaximum(500);
        jSliderAlcance.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        jSliderAlcance.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jSliderAlcanceStateChanged(evt);
            }
        });

        jLabel9.setText("A");

        jLabel10.setText("C0");

        jSliderEfeitoPepita.setBackground(new java.awt.Color(211, 211, 252));
        jSliderEfeitoPepita.setMaximum(10000);
        jSliderEfeitoPepita.setValue(0);
        jSliderEfeitoPepita.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        jSliderEfeitoPepita.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jSliderEfeitoPepitaStateChanged(evt);
            }
        });

        jTextFieldEfeitoPepita.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTextFieldEfeitoPepita.setText("0.0");
        jTextFieldEfeitoPepita.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldEfeitoPepitaActionPerformed(evt);
            }
        });
        jTextFieldEfeitoPepita.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                jTextFieldEfeitoPepitaFocusGained(evt);
            }
        });

        jLabel11.setText("C1");

        jSliderContribuicao.setBackground(new java.awt.Color(211, 211, 252));
        jSliderContribuicao.setMaximum(10000);
        jSliderContribuicao.setValue(2200);
        jSliderContribuicao.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        jSliderContribuicao.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jSliderContribuicaoStateChanged(evt);
            }
        });

        jTextFieldContribuicao.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTextFieldContribuicao.setText("0.22");
        jTextFieldContribuicao.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldContribuicaoActionPerformed(evt);
            }
        });
        jTextFieldContribuicao.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                jTextFieldContribuicaoFocusGained(evt);
            }
        });

        jLabel12.setText("Cut-off");

        jSliderCutOff.setBackground(new java.awt.Color(211, 211, 252));
        jSliderCutOff.setMaximum(10000);
        jSliderCutOff.setValue(8000);
        jSliderCutOff.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        jSliderCutOff.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jSliderCutOffStateChanged(evt);
            }
        });

        jTextFieldCutOff.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTextFieldCutOff.setText("0.8");
        jTextFieldCutOff.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldCutOffActionPerformed(evt);
            }
        });
        jTextFieldCutOff.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                jTextFieldCutOffFocusGained(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jSliderAlcance, javax.swing.GroupLayout.PREFERRED_SIZE, 192, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextFieldAlcance, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jSliderEfeitoPepita, javax.swing.GroupLayout.PREFERRED_SIZE, 192, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextFieldEfeitoPepita, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(jLabel11, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jSliderContribuicao, javax.swing.GroupLayout.PREFERRED_SIZE, 192, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextFieldContribuicao, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(jLabel12, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jSliderCutOff, javax.swing.GroupLayout.PREFERRED_SIZE, 192, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextFieldCutOff, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(10, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel9)
                    .addComponent(jTextFieldAlcance, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jSliderAlcance, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel10)
                    .addComponent(jTextFieldEfeitoPepita, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jSliderEfeitoPepita, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel11)
                    .addComponent(jTextFieldContribuicao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jSliderContribuicao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel12)
                    .addComponent(jTextFieldCutOff, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jSliderCutOff, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanelDesenho, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jComboBoxMetodo, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jComboBoxModelo, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 178, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel4)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(jTextFieldMMQ, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addComponent(jPanel4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanelDesenho, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jComboBoxMetodo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jComboBoxModelo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextFieldMMQ, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel4))))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jComboBoxModeloItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jComboBoxModeloItemStateChanged
        this.desenhaGrafico();
}//GEN-LAST:event_jComboBoxModeloItemStateChanged

    private void jComboBoxMetodoItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jComboBoxMetodoItemStateChanged
        this.desenhaGrafico();
}//GEN-LAST:event_jComboBoxMetodoItemStateChanged

    private void jTextFieldAlcanceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldAlcanceActionPerformed
        int value = jSliderAlcance.getValue();
        String digitado = jTextFieldAlcance.getText().replace(',', '.');
        try {
            double valor = Double.parseDouble(digitado);
            if ((int) valor <= jSliderAlcance.getMaximum()) {
                jTextFieldAlcance.setText("" + (int) valor);
                jSliderAlcance.setValue((int) valor);
            } else {
                jTextFieldAlcance.setText("" + value);
                jSliderAlcance.setValue(value);
            }
        } catch (Exception e) {
            jTextFieldAlcance.setText("" + value);
            jSliderAlcance.setValue(value);
        }
        this.desenhaGrafico();
}//GEN-LAST:event_jTextFieldAlcanceActionPerformed

    private void jTextFieldAlcanceFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTextFieldAlcanceFocusGained
        jTextFieldAlcance.setSelectionStart(0);
        jTextFieldAlcance.setSelectionEnd(jTextFieldAlcance.getText().length());
}//GEN-LAST:event_jTextFieldAlcanceFocusGained

    private void jSliderAlcanceStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jSliderAlcanceStateChanged
        this.desenhaGrafico();
}//GEN-LAST:event_jSliderAlcanceStateChanged

    private void jSliderEfeitoPepitaStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jSliderEfeitoPepitaStateChanged
        this.desenhaGrafico();
}//GEN-LAST:event_jSliderEfeitoPepitaStateChanged

    private void jTextFieldEfeitoPepitaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldEfeitoPepitaActionPerformed
        int value = jSliderEfeitoPepita.getValue();
        String digitado = jTextFieldEfeitoPepita.getText().replace(',', '.');
        try {
            double valor = Double.parseDouble(digitado);
            if ((int) (valor * 10000) <= jSliderEfeitoPepita.getMaximum()) {
                jTextFieldEfeitoPepita.setText("" + valor);
                jSliderEfeitoPepita.setValue((int) (valor * 10000));
            } else {
                jTextFieldEfeitoPepita.setText("" + value);
                jSliderEfeitoPepita.setValue(value);
            }
        } catch (Exception e) {
            jTextFieldEfeitoPepita.setText("" + value);
            jSliderEfeitoPepita.setValue(value);
        }
}//GEN-LAST:event_jTextFieldEfeitoPepitaActionPerformed

    private void jTextFieldEfeitoPepitaFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTextFieldEfeitoPepitaFocusGained
        jTextFieldEfeitoPepita.setSelectionStart(0);
        jTextFieldEfeitoPepita.setSelectionEnd(jTextFieldEfeitoPepita.getText().length());
}//GEN-LAST:event_jTextFieldEfeitoPepitaFocusGained

    private void jSliderContribuicaoStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jSliderContribuicaoStateChanged
        this.desenhaGrafico();
}//GEN-LAST:event_jSliderContribuicaoStateChanged

    private void jTextFieldContribuicaoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldContribuicaoActionPerformed
        int value = jSliderContribuicao.getValue();
        String digitado = jTextFieldContribuicao.getText().replace(',', '.');
        try {
            double valor = Double.parseDouble(digitado);
            if ((int) (valor * 10000) <= jSliderContribuicao.getMaximum()) {
                jTextFieldContribuicao.setText("" + valor);
                jSliderContribuicao.setValue((int) (valor * 10000));
            } else {
                jTextFieldContribuicao.setText("" + value);
                jSliderContribuicao.setValue(value);
            }
        } catch (Exception e) {
            jTextFieldContribuicao.setText("" + value);
            jSliderContribuicao.setValue(value);
        }
}//GEN-LAST:event_jTextFieldContribuicaoActionPerformed

    private void jTextFieldContribuicaoFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTextFieldContribuicaoFocusGained
        jTextFieldContribuicao.setSelectionStart(0);
        jTextFieldContribuicao.setSelectionEnd(jTextFieldContribuicao.getText().length());
}//GEN-LAST:event_jTextFieldContribuicaoFocusGained

    private void jSliderCutOffStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jSliderCutOffStateChanged
        this.desenhaGrafico();
}//GEN-LAST:event_jSliderCutOffStateChanged

    private void jTextFieldCutOffActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldCutOffActionPerformed
        String digitado = jTextFieldCutOff.getText().replace(',', '.');
        try {
            double valor = Double.parseDouble(digitado);
            if ((int) (valor * 10000) <= jSliderCutOff.getMaximum()) {
                jTextFieldCutOff.setText("" + valor);
                jSliderCutOff.setValue((int) (valor * 10000));
            } else {
                jTextFieldCutOff.setText("" + (jSliderCutOff.getMaximum() / 2) / 10000);
                jSliderCutOff.setValue(jSliderCutOff.getMaximum() / 2);
            }
        } catch (Exception e) {
            jTextFieldCutOff.setText("" + (jSliderCutOff.getMaximum() / 2) / 10000);
            jSliderCutOff.setValue(jSliderCutOff.getMaximum() / 2);
        }
}//GEN-LAST:event_jTextFieldCutOffActionPerformed

    private void jTextFieldCutOffFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTextFieldCutOffFocusGained
        jTextFieldCutOff.setSelectionStart(0);
        jTextFieldCutOff.setSelectionEnd(jTextFieldCutOff.getText().length());
}//GEN-LAST:event_jTextFieldCutOffFocusGained
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox jComboBoxMetodo;
    private javax.swing.JComboBox jComboBoxModelo;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanelDesenho;
    private javax.swing.JSlider jSliderAlcance;
    private javax.swing.JSlider jSliderContribuicao;
    private javax.swing.JSlider jSliderCutOff;
    private javax.swing.JSlider jSliderEfeitoPepita;
    private javax.swing.JTextField jTextFieldAlcance;
    private javax.swing.JTextField jTextFieldContribuicao;
    private javax.swing.JTextField jTextFieldCutOff;
    private javax.swing.JTextField jTextFieldEfeitoPepita;
    private javax.swing.JTextField jTextFieldMMQ;
    // End of variables declaration//GEN-END:variables

    public void desenhaGrafico() {
        jTextFieldAlcance.setText("" + jSliderAlcance.getValue());
        jTextFieldEfeitoPepita.setText("" + ((double) jSliderEfeitoPepita.getValue() / 10000));
        jTextFieldContribuicao.setText("" + ((double) jSliderContribuicao.getValue() / 10000));
        jTextFieldCutOff.setText("" + ((double) jSliderCutOff.getValue() / 10000));

        param.setModeloMatematico((String) jComboBoxModelo.getSelectedItem());
        param.setMetodoEstimacao((String) jComboBoxMetodo.getSelectedItem());
        param.getModelo().setAlcance(Integer.parseInt(jTextFieldAlcance.getText()));
        param.getModelo().setEfeitoPepita(Double.parseDouble(jTextFieldEfeitoPepita.getText()));
        param.getModelo().setContribuicao(Double.parseDouble(jTextFieldContribuicao.getText()));
        param.getPontos().setCutoff(Double.parseDouble(jTextFieldCutOff.getText()) * param.getPontos().getMaiorH());

        jPanelDesenho.setBorder(javax.swing.BorderFactory.createTitledBorder(null, param.getMetodoEstimacao(), javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), new java.awt.Color(0, 0, 153)));

        if (param.getMetodoEstimacao().equals("Cressie")) {
            param.setXmax(param.getPontos().getCressie().getXmax());
            param.setYmax(param.getPontos().getCressie().getYmax());
        } else {
            if (param.getMetodoEstimacao().equals("Matheron")) {
                param.setXmax(param.getPontos().getMatheron().getXmax());
                param.setYmax(param.getPontos().getMatheron().getYmax());
            } else {
                if (param.getMetodoEstimacao().equals("Pairwise")) {
                    param.setXmax(param.getPontos().getPairwise().getXmax());
                    param.setYmax(param.getPontos().getPairwise().getYmax());
                } else {
                    param.setXmax(width);
                    param.setYmax(height);
                }
            }
        }

        ((Desenho) jPanelDesenho).setaVariaveis(param, height, width);
        jPanelDesenho.repaint();
        jTextFieldMMQ.setText("" + param.getModelo().getMmq());
        if ((!param.getMetodoEstimacao().equals("Metodo")) && (!param.getModeloMatematico().equals("Modelo"))) {
            jMenuItemAG.setEnabled(true);
        }else{
            jMenuItemAG.setEnabled(false);
        }
    }

    public JSlider getJSliderAlcance(){
        return this.jSliderAlcance;
    }

    public JSlider getJSliderEfeitoPepita(){
        return this.jSliderEfeitoPepita;
    }

    public JSlider getJSliderContribuicao(){
        return this.jSliderContribuicao;
    }

    public JTextField getJTextFieldAlcance(){
        return this.jTextFieldAlcance;
    }

    public JTextField getJTextFieldEfeitoPepita(){
        return this.jTextFieldEfeitoPepita;
    }

    public JTextField getJTextFieldContribuicao(){
        return this.jTextFieldContribuicao;
    }
}
